// 模拟常用高阶函数: map every some

// map
const map = (array, fn) => {
  let res = []
  for (let item of array) { 
    res.push(fn(item)) 
  }
  return res
}

// 测试
// let arr = [1, 2, 3, 4, 5, 6, 7]
// arr = map(arr, v => v * v)
// console.log(arr) // [  1,  4,  9, 16, 25, 36, 49 ]

// every  数组里每个是否符合条件
const every = (array, fn) => { 
  let bool = true
  for (let item of array) { 
    bool = fn(item)
    if(!bool) break
  }
  return bool
}

// 测试
// let arr = [1, 2, 3, 4, 5, 6, 7]
// arr = every(arr, v => v > 5)
// console.log(arr) // false

// some  数组里是否有一个符合条件
const some = (array, fn) => { 
  let bool = false
  for (let item of array) { 
    bool = fn(item)
    if(bool) break
  }
  return bool
}

// 测试
// let arr = [1, 2, 3, 4, 5, 6, 7]
// arr = some(arr, v => v > 5)
// console.log(arr) // true

// TODO: reduce, sort